package com.csproj.dispatch.service;

import com.csproj.dispatch.domain.DispatchRoute;
import com.csproj.dispatch.repository.DispatchRouteRepository;
import com.csproj.dispatch.service.dto.DispatchRouteDTO;
import com.csproj.dispatch.service.mapper.DispatchRouteMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Service Implementation for managing DispatchRoute.
 */
@Service
@Transactional
public class DispatchRouteService {

    private final Logger log = LoggerFactory.getLogger(DispatchRouteService.class);

    private final DispatchRouteRepository dispatchRouteRepository;

    private final DispatchRouteMapper dispatchRouteMapper;

    public DispatchRouteService(DispatchRouteRepository dispatchRouteRepository, DispatchRouteMapper dispatchRouteMapper) {
        this.dispatchRouteRepository = dispatchRouteRepository;
        this.dispatchRouteMapper = dispatchRouteMapper;
    }

    /**
     * Save a dispatchRoute.
     *
     * @param dispatchRouteDTO the entity to save
     * @return the persisted entity
     */
    public DispatchRouteDTO save(DispatchRouteDTO dispatchRouteDTO) {
        log.debug("Request to save DispatchRoute : {}", dispatchRouteDTO);
        DispatchRoute dispatchRoute = dispatchRouteMapper.toEntity(dispatchRouteDTO);
        dispatchRoute = dispatchRouteRepository.save(dispatchRoute);
        return dispatchRouteMapper.toDto(dispatchRoute);
    }

    /**
     * Get all the dispatchRoutes.
     *
     * @return the list of entities
     */
    @Transactional(readOnly = true)
    public List<DispatchRouteDTO> findAll() {
        log.debug("Request to get all DispatchRoutes");
        return dispatchRouteRepository.findAll().stream()
            .map(dispatchRouteMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));
    }

}
